import request from '@/utils/request'

const ha_userApi = {
  list: '/ha_user/list',
  save: '/ha_user/save',
  view: '/ha_user/view',
  freeze: '/ha_user/freezeUser',
  dels: '/ha_user/batchDel',
  output: '/ha_user/output',
  updatePassword: '/ha_user/updatePassword',
  tree: '/account/ha_user/tree',
  findUserTree: '/approve/ha_user/findUserTree',
  queryUserTreeByDepartids: '/apl_main/queryUserTreeByDepartids',
}

/**
 * 查询部门或单位用户树
 */
 export function findUserTree (departid, pageInfo) {
  return request({
    url: ha_userApi.findUserTree,
    method: 'post',
    params: { departid },
    data: pageInfo
  })
}

/**
 * 修改密码
 */
export function updatePassword (parameter) {
  return request({
    url: ha_userApi.updatePassword,
    method: 'post',
    params: parameter
  })
}

/**
 * 导出用户
 */
export function output (data) {
  return request({
    url: ha_userApi.output,
    method: 'post',
    data: data,
    responseType: 'blob'
  })
}
/**
 * 批量删除用户
 * @param {*} parameter
 */
export function delHa_users (ids) {
  return request({
    url: ha_userApi.dels + '/' + ids,
    method: 'post'
  })
}
/**
 * 冻结用户
 * @param {*} id
 */
export function delHa_user (id) {
  return request({
    url: ha_userApi.freeze + '/' + id,
    method: 'post'
  })
}
/**
 * 查看、编辑用户
 * @param {*} id
 */
export function viewHa_user (id) {
  return request({
    url: ha_userApi.view + '/' + id,
    method: 'post'
  })
}
/**
 * 保存用户
 * @param {*} parameter
 */
export function saveHa_user (parameter) {
  return request({
    url: ha_userApi.save,
    method: 'post',
    data: parameter
  })
}
/**
 * 查询用户列表
 * @param {*} parameter
 */
export function queryHa_userList (parameter) {
  return request({
    url: ha_userApi.list,
    method: 'post',
    data: parameter
  })
}

/**
 * 查询用户树
 * @returns
 */
export function queryUserTree (params) {
  if(params.departid == 0) {
    delete params.departid
  }
  return request({
    url: ha_userApi.tree,
    method: 'post',
    params: params
  })
}

/**
 * 查询用户树
 * @returns
 */
 export function queryUserTreeByDepartids (departList) {
  if(departList[0] == 0) {
    departList.length = '0'
  }
  return request({
    url: ha_userApi.queryUserTreeByDepartids,
    method: 'post',
    data: departList
  })
}
